<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Adds a child document for block indexing</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="class.solrinputdocument.html">« SolrInputDocument</a></li>
      <li style="float: right;"><a href="solrinputdocument.addchilddocuments.html">SolrInputDocument::addChildDocuments »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.solrinputdocument.html">SolrInputDocument</a></li>
    <li>Adds a child document for block indexing</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="solrinputdocument.addchilddocument" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SolrInputDocument::addChildDocument</h1>
  <p class="verinfo">(PECL solr &gt;= 2.3.0)</p><p class="refpurpose"><span class="refname">SolrInputDocument::addChildDocument</span> &mdash; <span class="dc-title">Adds a child document for block indexing</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-solrinputdocument.addchilddocument-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>SolrInputDocument::addChildDocument</strong></span>(<span class="methodparam"><span class="type"><a href="class.solrinputdocument.html" class="type SolrInputDocument">SolrInputDocument</a></span> <code class="parameter">$child</code></span>): <span class="type"><span class="type void">void</span></span></div>

  <p class="para rdfs-comment">
    Adds a child document to construct a document block with nested documents.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-solrinputdocument.addchilddocument-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">child</code></dt>

    <dd>

     <p class="para">
      A <span class="type"><a href="class.solrinputdocument.html" class="type SolrInputDocument">SolrInputDocument</a></span> object.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-solrinputdocument.addchilddocument-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   没有返回值。
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-solrinputdocument.addchilddocument-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   Throws <span class="classname"><a href="class.solrillegalargumentexception.html" class="classname">SolrIllegalArgumentException</a></span> on failure.
  </p>
  <p class="para">
   Throws <span class="classname"><a href="class.solrexception.html" class="classname">SolrException</a></span> on internal failure.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-solrinputdocument.addchilddocument-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-4630">
   <p><strong>示例 #1 <span class="function"><strong>SolrInputDocument::addChildDocument()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">include&nbsp;</span><span style="color: #DD0000">"bootstrap.php"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;array<br />(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'hostname'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_HOSTNAME</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'login'&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_USERNAME</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'password'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_PASSWORD</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'port'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_PORT</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'path'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">SOLR_SERVER_STORE_PATH</span><span style="color: #007700">,<br />);<br /><br /></span><span style="color: #0000BB">$client&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrClient</span><span style="color: #007700">(</span><span style="color: #0000BB">$options</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$product&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrInputDocument</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$product</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'id'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'P-BLACK'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$product</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'cat'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'tshirt'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$product</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'cat'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'polo'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$product</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'content_type'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'product'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$small&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrInputDocument</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$small</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'id'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'TS-BLK-S'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$small</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'content_type'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'sku'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$small</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'size'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'S'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$small</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'inventory'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">100</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$medium&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrInputDocument</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$medium</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'id'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'TS-BLK-M'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$medium</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'content_type'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'sku'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$medium</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'size'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'M'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$medium</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'inventory'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">200</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$large&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrInputDocument</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$large</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'id'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'TS-BLK-L'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$large</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'content_type'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'sku'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$large</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'size'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'L'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$large</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'inventory'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">300</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;add&nbsp;child&nbsp;documents&nbsp;<br /></span><span style="color: #0000BB">$product</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addChildDocument</span><span style="color: #007700">(</span><span style="color: #0000BB">$small</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$product</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addChildDocument</span><span style="color: #007700">(</span><span style="color: #0000BB">$medium</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$product</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addChildDocument</span><span style="color: #007700">(</span><span style="color: #0000BB">$large</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;add&nbsp;product&nbsp;document&nbsp;block&nbsp;to&nbsp;the&nbsp;index<br /></span><span style="color: #0000BB">$updateResponse&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$client</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addDocument</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$product</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">,&nbsp;</span><span style="color: #FF8000">//&nbsp;overwrite&nbsp;if&nbsp;the&nbsp;document&nbsp;exists<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">10000&nbsp;</span><span style="color: #FF8000">//&nbsp;commit&nbsp;within&nbsp;10&nbsp;seconds<br /></span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$updateResponse</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getResponse</span><span style="color: #007700">());</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
SolrObject Object
(
    [responseHeader] =&gt; SolrObject Object
        (
            [status] =&gt; 0
            [QTime] =&gt; 5
        )
)
</pre></div>
   </div>
  </div>
 </div>



 <div class="refsect1 seealso" id="refsect1-solrinputdocument.addchilddocument-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="methodname"><a href="solrinputdocument.addchilddocuments.html" class="methodname" rel="rdfs-seeAlso">SolrInputDocument::addChildDocuments()</a> - Adds an array of child documents</span></li>
   <li class="member"><span class="methodname"><a href="solrinputdocument.haschilddocuments.html" class="methodname" rel="rdfs-seeAlso">SolrInputDocument::hasChildDocuments()</a> - Returns true if the document has any child documents</span></li>
   <li class="member"><span class="methodname"><a href="solrinputdocument.getchilddocuments.html" class="methodname" rel="rdfs-seeAlso">SolrInputDocument::getChildDocuments()</a> - Returns an array of child documents (SolrInputDocument)</span></li>
   <li class="member"><span class="methodname"><a href="solrinputdocument.getchilddocumentscount.html" class="methodname" rel="rdfs-seeAlso">SolrInputDocument::getChildDocumentsCount()</a> - Returns the number of child documents</span></li>
  </ul>
 </div>


</div></div></div></body></html>